Micron Document




Conditional (computer programming)
part 2/26 · 46.2 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terminology

Conditional statements are imperative constructs executed for side-effect, while conditional expressions return values. Many programming languages (such as C) have distinct conditional statements and conditional expressions. Although in pure functional programming, conditional expressions do not have side-effects, many languages with conditional expressions (such as Lisp) support conditional side-effects.

If–then(–else)

The if–then or if–then–else construction is used in many programming languages. Although the syntax varies from language to language, the basic structure (in pseudocode form) looks like this:

If (Boolean condition) Then
(consequent)
Else
(alternative)
End If

For example:

If stock = 0 Then
message = order new stock
Else
message = there is stock
End If

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────